package org.redis.test;

import org.junit.Test;
import org.taotao.jedis.JedisUtils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisDemo1 {
    
    /**
     * 单实例链接redis数据库
     */
    @Test
    public void run1(){
        Jedis jedis = new Jedis("192.168.170.131",6379);
        //jedis.set("name","习文文");
        System.out.println(jedis.get("name"));
    }
    
    /**
     * Jedis连接池
     */
    @Test
    public void run2(){
        //1.设置连接池的配置对象
        JedisPoolConfig config = new JedisPoolConfig();
        //2.设置池中最大连接数【可选】
        config.setMaxTotal(50);
        //3.设置空闲时池中保有的最大连接数【可选】
        config.setMaxIdle(10);
        //4.设置连接池对象
        JedisPool pool = new JedisPool(config,"192.168.170.131",6379);
        //5.从池中获取连接对象
        Jedis jedis = pool.getResource();
        System.out.println(jedis.get("name"));
        jedis.close();
    }
    
    @Test
    public void run3(){
        Jedis jedis = JedisUtils.getJedis();
        System.out.println(jedis.get("name"));
    }
}
